package com.lukstron.youko;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import android.os.Environment;

public class DataWriter {
	FileWriter _fileWriter = null;

	public DataWriter(String name) throws IOException {
		File dir = Environment.getExternalStorageDirectory();
		File folder = new File(dir, "GeoRes");
		if (!folder.exists()) {
			folder.mkdirs();
		}
		File file = new File(folder, name);
		Boolean exists = file.exists();
		_fileWriter = new FileWriter(file);
		if (!exists) {
			_fileWriter.append(_getHeader());
			_fileWriter.append("\n");
			_fileWriter.flush();
		}
	}

	protected String _getHeader() {
		StringBuilder stringBuilder = null;
		stringBuilder = new StringBuilder();
		stringBuilder.append("Datum");
		stringBuilder.append("\t");
		stringBuilder.append("Depth");
		stringBuilder.append("\t");
		stringBuilder.append("Axis");
		stringBuilder.append("\t");
		stringBuilder.append("A");
		stringBuilder.append("\t");
		stringBuilder.append("M");
		stringBuilder.append("\t");
		stringBuilder.append("N");
		stringBuilder.append("\t");
		stringBuilder.append("B");
		stringBuilder.append("\t");
		stringBuilder.append("SP");
		stringBuilder.append("\t");
		stringBuilder.append("I:AB");
		stringBuilder.append("\t");
		stringBuilder.append("V:MN");
		stringBuilder.append("\t");
		stringBuilder.append("Time");
		return stringBuilder.toString();
	}

	public void append(String string) throws IOException {
		_fileWriter.append(string);
		_fileWriter.flush();
	}

	public void close() {
		try {
			_fileWriter.close();
		} catch (IOException e) {

		}
	}

}
